/**
 * Copyright &copy; 2012-2016 <a href="https://github.com/thinkgem/jeesite">JeeSite</a> All rights reserved.
 */
package com.thinkgem.jeesite.modules.hk.sys.service.job;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import com.thinkgem.jeesite.common.persistence.Page;
import com.thinkgem.jeesite.common.service.CrudService;
import com.thinkgem.jeesite.common.utils.StringUtils;
import com.thinkgem.jeesite.modules.hk.sys.entity.job.HkUserResumeDelivery;
import com.thinkgem.jeesite.modules.hk.sys.dao.job.HkUserResumeDeliveryDao;
import com.thinkgem.jeesite.modules.hk.sys.entity.job.HkUserResumeDeliveryLog;
import com.thinkgem.jeesite.modules.hk.sys.dao.job.HkUserResumeDeliveryLogDao;

/**
 * 简历投递Service
 * @author 罗天文
 * @version 2018-07-20
 */
@Service
@Transactional(readOnly = true)
public class HkUserResumeDeliveryService extends CrudService<HkUserResumeDeliveryDao, HkUserResumeDelivery> {

	@Autowired
	private HkUserResumeDeliveryLogDao hkUserResumeDeliveryLogDao;
	
	public HkUserResumeDelivery get(String id) {
		HkUserResumeDelivery hkUserResumeDelivery = super.get(id);
		hkUserResumeDelivery.setHkUserResumeDeliveryLogList(hkUserResumeDeliveryLogDao.findList(new HkUserResumeDeliveryLog(hkUserResumeDelivery)));
		return hkUserResumeDelivery;
	}
	
	public List<HkUserResumeDelivery> findList(HkUserResumeDelivery hkUserResumeDelivery) {
		return super.findList(hkUserResumeDelivery);
	}
	
	public Page<HkUserResumeDelivery> findPage(Page<HkUserResumeDelivery> page, HkUserResumeDelivery hkUserResumeDelivery) {
		return super.findPage(page, hkUserResumeDelivery);
	}
	
	@Transactional(readOnly = false)
	public void save(HkUserResumeDelivery hkUserResumeDelivery) {
		super.save(hkUserResumeDelivery);
		for (HkUserResumeDeliveryLog hkUserResumeDeliveryLog : hkUserResumeDelivery.getHkUserResumeDeliveryLogList()){
			if (hkUserResumeDeliveryLog.getId() == null){
				continue;
			}
			if (HkUserResumeDeliveryLog.DEL_FLAG_NORMAL.equals(hkUserResumeDeliveryLog.getDelFlag())){
				if (StringUtils.isBlank(hkUserResumeDeliveryLog.getId())){
					hkUserResumeDeliveryLog.setDeliveryId(hkUserResumeDelivery);
					hkUserResumeDeliveryLog.preInsert();
					hkUserResumeDeliveryLogDao.insert(hkUserResumeDeliveryLog);
				}else{
					hkUserResumeDeliveryLog.preUpdate();
					hkUserResumeDeliveryLogDao.update(hkUserResumeDeliveryLog);
				}
			}else{
				hkUserResumeDeliveryLogDao.delete(hkUserResumeDeliveryLog);
			}
		}
	}
	
	@Transactional(readOnly = false)
	public void delete(HkUserResumeDelivery hkUserResumeDelivery) {
		super.delete(hkUserResumeDelivery);
		hkUserResumeDeliveryLogDao.delete(new HkUserResumeDeliveryLog(hkUserResumeDelivery));
	}
	
}